function clear(){
	var f = document.getElementById("busquedaForm");
	Z.ClearForm(f);
}

function detalle(record) {
	try {
		var f = document.getElementById("detalleForm");
		f.elements['idCert'].value = record.getData('folio');
		f.action = Context.Reporte;
		f.submit();
		
	} catch (e) {
		alert(e);
	}
}


function valida() {
	try {
		var f = document.getElementById("busquedaForm");
		var callback = new Z.JsonCall();
		callback.exito = function(data) {
			Z.Publicar('div.fecha','')
			busqueda();
		};
		callback.fallo = function(messages) {
		};
		Z.ShowWait();
		Y.util.Connect.setForm(f);
		var request = Y.util.Connect.asyncRequest('POST', Context.Valida,
				callback);

	} catch (e) {
		alert("valida: " + e + e.description);
	}
};


function busqueda() {
	try {
		var f = document.getElementById("busquedaForm");
		var callback = new Z.JsonCall();
		callback.exito = function(data) {
			Context.table.clear();
			Context.tableD.clear();
			myDataTable.insertar(data.ResultSet.Result);
		};
				
		Z.ShowWait();
		Y.util.Connect.setForm(f);
		var request = Y.util.Connect.asyncRequest('POST', Context.Busqueda,
				callback);

	} catch (e) {
		alert("busqueda: " + e + e.description);
	}
};



function creardialogo() {
	Context.dialog1 = new Y.widget.Dialog("dialog1", {
		width : "80em",
		height : "45em",
		fixedcenter : true,
		visible : false,
		constraintoviewport : false,
		modal : true,
		zindex : 5,
		buttons : [ {
			text : "Aceptar",
			handler : function(){
				Context.dialog1.hide();
			},
			isDefault : true
		}, {
			text : "Cancelar",
			handler : function(){
				Context.dialog1.hide();
			}
		} ]
	});
	var kw = new Y.util.KeyListener(document, {
		keys : 27
	}, {
		fn : Context.dialog1.hide,
		scope : Context.dialog1,
		correctScope : true
	});
	kw.enable();
	Context.dialog1.render(document.body);
	
	
	Context.dialog2 = new Y.widget.Dialog("dialog2", {
		width : "80em",
		height : "45em",
		fixedcenter : true,
		visible : false,
		constraintoviewport : false,
		modal : true,
		zindex : 5,
		buttons : [ {
			text : "Aceptar",
			handler : function(){
				Context.dialog2.hide();
			},
			isDefault : true
		} ]
	});
	var kw = new Y.util.KeyListener(document, {
		keys : 27
	}, {
		fn : Context.dialog2.hide,
		scope : Context.dialog2,
		correctScope : true
	});
	kw.enable();
	Context.dialog2.render(document.body);
	
	
}



function crearbotones() {

	
	new Y.widget.Button("buscarbutton", {
		onclick : {
			fn : function() {
				valida() ;
			}
		}
	});

};

Y.util.Event.onDOMReady(function() {
	try {
		creardatatable();
		creardialogo();
		crearbotones();
		creardatatableDetalle();
		//Context.table.update();
	} catch (e) {
		alert(e);
	}
});
